import 'package:dio/dio.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:jyofservice/bean/delay_data_entity.dart';
import 'package:jyofservice/generated/json/base/json_convert_content.dart';
import 'package:jyofservice/util/AesUtil.dart';
import 'package:jyofservice/util/webconfig.dart';

class FunctionNotRead{
  //获取调度列表数据
  Future getDiaoDuListData() async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? key = sharedPreferences.getString("key");
    String aesData = await AesUtil.encodeBase64();
    var data = {
      "key": key,
      "view": 'GetMyAndChildrenWorkForm',
      "wherestr": "1=1 and StateName!='待下发' and State=2",  //State=2 待下发工单
      "sortName": "CreateDate",
      "sortOrder": "desc",
      "ClientType": "phone",
      "ClientKey": aesData
    };
    print(data.toString());
    Response response = await Dio().post(
        WebConfig().baseUrl + "DB/postrowdataforlayui",
        data: data);
    print(response.data.toString());
    if (response.data["code"] == 0) {
      return response.data["data"].length;
    }
    return 0;
  }

  //获取我的工单列表数据
  Future getWoDeListData() async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? key = sharedPreferences.getString("key");
    String aesData = await AesUtil.encodeBase64();
    var data = {
      "key": key,
      "view": 'GetMySelfWaitDoWorkConfirm',
      "wherestr": "1=1 and StateName!='待下发'",
      "sortName": "CreateDate",
      "sortOrder": "desc",
      "ClientType": "phone",
      "ClientKey": aesData
    };
    print(data.toString());

    Response response = await Dio().post(
        WebConfig().baseUrl + "DB/postrowdataforlayui",
        data: data);
    print(response.data.toString());

    if (response.data["code"] == 0) {
      return response.data["data"].length;
    }
    return 0;
  }

  //缓办审批
  Future getDelyData() async{
    SharedPreferences sharedPreferences =
    await SharedPreferences.getInstance();
    String? key = sharedPreferences.getString("key");
    String aesData = await AesUtil.encodeBase64();
    var data = {
      "key": key,
      "view": 'GetMyDepartmentGDHuanBanRequest',
      "wherestr": "State in (1)",
      "limit": 65532,
      "page": 1,
      "sortName": "CreateDate",
      "sortOrder": "desc",
      "ClientType": "phone",
      "ClientKey": aesData
    };
    print(data.toString());

    Response response = await Dio().post(
        WebConfig().baseUrl + "DB/postrowdataforlayui",
        data: data);
    print("审批："+response.data.toString());

    if (response.data["code"] == 0) {
      DelayDataEntity? dataEntity = DelayDataEntity().fromJson(response.data);
      if(dataEntity?.data != null){
        return dataEntity?.data!.length;
      }
      return 0;
    }
    return 0;
  }

  Future getCheckData() async{
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? key = sharedPreferences.getString("key");
    String aesData = await AesUtil.encodeBase64();
    var data = {
      "key": key,
      "view": "GetMySelfWaitDoWork",
      "wherestr": "1=1",
      "limit": 65532,
      "page": 1,
      "sortName": "CreateDate",
      "sortOrder": "desc",
      "ClientType": "phone",
      "ClientKey": aesData
    };
    print(data.toString());

    Response response = await Dio()
        .post(WebConfig().baseUrl + "DB/postrowdataforlayui", data: data);
    print(response.data.toString());

    if (response.data["code"] == 0) {
      return response.data["data"].length;

    }
    return 0;
  }
}